<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>

<!--form表单方式-->
<!--<form action="http://127.0.0.1:8080/user/login" method="post">
    <div><label> User Name : <input type="text" name="username"/> </label></div>
    <div><label> Password: <input type="password" name="password"/> </label></div>
    <div><input type="submit" value="确定"/></div>
</form>-->

<!--ajax请求方式-->
<div>
    <div><label> User Name : <input type="text" name="username"/> </label></div>
    <div><label> Password: <input type="password" name="password"/> </label></div>
    <div><input type="button" id="submit" value="确定"/></div>
</div>

</body>
<script src="http://127.0.0.1:8080/js/jQuery-v3.6.0.js"></script>
<script>

    $(function(){


        $('#submit').click(function(){
            var username = $('input[name=username]').val();
            var password = $('input[name=password]').val();

            var formData = new FormData();
            formData.append('username',username);
            formData.append('password',password);

            $.ajax({
                type : 'post',
                url : 'http://127.0.0.1:8080/login',
                processData : false,
                contentType : false,
                data : formData,
                success : function(res){
                    alert(JSON.stringify(res));
                }
            });

        });


    })

</script>
</html>